//
//  STWelcomeController.swift
//  STVVeibo
//
//  Created by leergou on 16/7/22.
//  Copyright © 2016年 WhiteHouse. All rights reserved.
//

import UIKit
//import SDWebImage

class STWelcomeController: UIViewController {
    
    override func loadView() {
        view = bgImageView

    }

    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        iconImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(view).offset(100)
        }
        
        // 设置约束动画
        UIView.animateWithDuration(3, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                
                // 上一个动画完成,进行下一个动画
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    
                    self.messageLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        
                        NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootViewContrller, object: "welcome")
                })
                
        }
        
        
    }
    
    
    //MAKR: - setupUI
    func setupUI(){
        
        // 添加控件
        view.addSubview(iconImageView)
        view.addSubview(messageLabel)
        
        // 添加约束
        iconImageView.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view)
            make.top.equalTo(iconImageView.snp_bottom).offset(16)
        }
    }

    //MAKR: - lazy
    private lazy var bgImageView: UIImageView = UIImageView(imgName: "ad_background")
    
    private lazy var iconImageView: UIImageView = {
        let imgView = UIImageView(imgName: "avatar_default_big")
        imgView.st_setImage(STUserAccountViewModel.sharedUserAccountTools.userAccount?.avatar_large, placeholderImgName: "avatar_default_big")
        imgView.layer.cornerRadius = 45
        imgView.layer.borderWidth = 2
        imgView.layer.borderColor = ThemeColor.CGColor
        imgView.layer.masksToBounds = true
        return imgView
    }()
    
    private lazy var messageLabel: UILabel = {
        let label = UILabel (font: 18, textColor:UIColor.darkGrayColor())
            label.text = "欢迎回来"
            label.textAlignment = .Center
            label.alpha = 0
          return label
    }()
    
    
}
